#!/bin/bash

# Snakes on a Payload
# Copyright (C) 2011 CORE Security Technologies
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# Authors:
# 2011/09/11 - Pedro Varangot (pvarangot@)
# 2011/09/11 - Fernando Russ (fruss@)

TESTCASE=$1
TEST_FILE=${TESTCASE##*/}
TEST_RUNNER=`pwd`/tests/android-arm/load_code_and_run
TEST_RUNNER_HASH=`sha1sum -b $TEST_RUNNER | cut -c-40`
if [ ! -f "$TEST_RUNNER.$TEST_RUNNER_HASH" ]; then
    $s2l_android_arm_adb_tool push $TEST_RUNNER /data/tmp/load_code_and_run 2> /dev/null
    $s2l_android_arm_adb_tool shell chmod 777 /data/tmp/load_code_and_run
    touch $TEST_RUNNER.$TEST_RUNNER_HASH
fi
$s2l_android_arm_adb_tool push $TESTCASE /data/tmp 2> /dev/null
$s2l_android_arm_adb_tool shell /data/tmp/load_code_and_run /data/tmp/$TEST_FILE
